/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifRegistrarStockFisico.java
 *
 * Created on 17-sep-2010, 9:05:22
 */

package Inventario;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.beansbinding.AbstractBindingListener;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.AlmacenTO;
import suministros.ejb30.TO.DetalleInventarioTO;
import suministros.ejb30.TO.InventarioTO;
import suministros.ejb30.TO.SubAlmacenTO;
import suministros.ejb30.TO.ZonaTO;
import suministros.ejb30.entity.DetalleInventario;
import org.jdesktop.beansbinding.Binding;
import suministros.ejb30.TO.EmpresaTO;

/**
 *
 * @author Diana
 */
public class jifRegistrarStockFisico extends javax.swing.JInternalFrame {
    List<ZonaTO> zonas;
    List<EmpresaTO> empresas;
    List<AlmacenTO> almacenes;
    List<SubAlmacenTO> subalmacenes;
    List<DetalleInventarioTO> listadetallesInventario;
    private JTableBinding jTableBinding;
    int paginas=0;
    int paginaActual=0;
    boolean estado= false;

    /** Creates new form jifRegistrarStockFisico */
    public jifRegistrarStockFisico() {
        if(Listas.getInventario()){
            initComponents();
            empresas = Listas.getEmpresas();
            if(empresas.isEmpty()){
                this.jCheckBox1.setEnabled(false);
            }
            llenarDatosInventario();
            this.jCheckBox1.setSelected(false);
            this.llenarComboEmpresa();
            this.jcbEmpresa.setEnabled(false);
            this.jbtAnterior.setEnabled(false);
            this.jbtAnteriort.setEnabled(false);
            this.jbtSiguiente.setEnabled(false);
            this.jbtSiguientet.setEnabled(false);

        }
        else{
             Utiles_MensajesDialogo.mensajeAlerta("No se ha iniciado un inventario actualmente");
             this.dispose();
        }
      
       
    }
     private void llenarComboEmpresa() {
        empresas = null;
        List listaPaises_cbo = this.cboBeanBindingEmpresa1.getLista();
        listaPaises_cbo.clear();
        try
        {
          if(this.jCheckBox1.isSelected()){
                empresas = Listas.getEmpresas();
            }
            else{
                empresas = Listas.getEmpresaPrincipal();
            }
          this.cboBeanBindingEmpresa1.setLista(empresas);
          this.bindingGroup.bind();
          this.jcbEmpresa.updateUI();
          this.jcbEmpresa.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener empresas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
   
     public void llenarDatosInventario(){
        try {
            InventarioTO inv = GestionPedidosDelegate.getInstance().getDatosInventario();
            this.jlbInventario.setText(inv.getDescripcion());


        } catch (Exception ex) {
           Utiles_MensajesDialogo.mensajeAlerta("No se ha iniciado un inventario actualmente");
           this.jbtGenerar.setEnabled(false);
           this.jbtAceptar.setEnabled(false);
          
        }


     }
     /*public void actualizarTabla(){
        this.bindingGroup = new BindingGroup();
        this.bindingGroup.addBindingListener(new AbstractBindingListener() {
           @Override public void synced(Binding binding) {
            try{
                if(!listadetallesInventario.isEmpty()){
                    int selec=jtbDetalleInventario.getSelectedRow();
                    if(selec>-1){
                        estado=true;
                        actualizarTabla();
                    }
                }

            }catch(ArrayIndexOutOfBoundsException ex){
            }
                catch(Exception e){
                e.printStackTrace();
            }

            }
        });
        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ_WRITE, this.listadetallesInventario, this.jtbDetalleInventario);

        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${descAmbiente}"));

        columnBinding0.setColumnName("Ambiente");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descPabellon}"));

        columnBinding1.setColumnName("Pabellon");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${descEstante}"));

        columnBinding2.setColumnName("Estante");
        columnBinding2.setColumnClass(String.class);
        columnBinding2.setEditable(true);

        JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${descCasilla}"));

        columnBinding3.setColumnName("Casilla");
        columnBinding3.setColumnClass(String.class);
        columnBinding3.setEditable(false);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${codSuministro}"));

        columnBinding4.setColumnName("Suministro");
        columnBinding4.setColumnClass(String.class);
        columnBinding4.setEditable(false);
         JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

        columnBinding5.setColumnName("Descripcion");
        columnBinding5.setColumnClass(String.class);
        columnBinding5.setEditable(false);
         JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${unidad}"));

        columnBinding6.setColumnName("Unidad");
        columnBinding6.setColumnClass(String.class);
        columnBinding6.setEditable(false);

        JTableBinding.ColumnBinding columnBinding7 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidadActual}"));

        columnBinding7.setColumnName("Cantidad Actual");
        columnBinding7.setColumnClass(BigDecimal.class);
        columnBinding7.setEditable(false);

         JTableBinding.ColumnBinding columnBinding8 = this.jTableBinding.addColumnBinding(ELProperty.create("${existenciaFisica}"));

        columnBinding8.setColumnName("Existencia Fisica");
        columnBinding8.setColumnClass(BigDecimal.class);
        columnBinding8.setEditable(true);

        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();

        int[] porcentajes= {8,8,8,8,10,34,8,8,8};
        try {
            Utiles_Tabla.definirAnchoColumnasJTable(this.jtbDetalleInventario, porcentajes);
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }
     }*/
     public void actualizarTabla(){
        List<DetalleInventarioTO> listadetalles= this.recorrerTabla();
        this.bindingGroup = new BindingGroup();

        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ_WRITE, listadetalles, this.jtbDetalleInventario);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${codSuministro}"));

        columnBinding4.setColumnName("Sumi.");
        columnBinding4.setColumnClass(String.class);
        columnBinding4.setEditable(false);
         JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

        columnBinding5.setColumnName("Descripcion");
        columnBinding5.setColumnClass(String.class);
        columnBinding5.setEditable(false);
         JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${unidad}"));

        columnBinding6.setColumnName("Unidad");
        columnBinding6.setColumnClass(String.class);
        columnBinding6.setEditable(false);

        JTableBinding.ColumnBinding columnBinding7 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidadActual}"));

        columnBinding7.setColumnName("Cant.Actual");
        columnBinding7.setColumnClass(BigDecimal.class);
        columnBinding7.setEditable(false);

         JTableBinding.ColumnBinding columnBinding8 = this.jTableBinding.addColumnBinding(ELProperty.create("${existenciaFisica}"));

        columnBinding8.setColumnName("Cant.Fisica");
        columnBinding8.setColumnClass(BigDecimal.class);
        columnBinding8.setEditable(true);

        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();

        int[] porcentajes= {8,8,8,8,10,34,8,8,8};
        try {
            Utiles_Tabla.definirAnchoColumnasJTable(this.jtbDetalleInventario, porcentajes);
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }
     }

     public void llenarSuministros(){
        /*  if(!listadetallesInventario.isEmpty()){
             llenarDatos();
         }*/
        
        try {
            String empresa=((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getCodigo();
            listadetallesInventario = GestionPedidosDelegate.getInstance().getListaDetalleInventario(empresa,Listas.retornaInventario().getCodigo());
            this.paginas=(int)Math.ceil(listadetallesInventario.size()/15);
            if(listadetallesInventario.isEmpty()){
                 Utiles_MensajesDialogo.mensajeAlerta("No se han encontrado suministros en almacen");
            }
            else{
                this.jbtAceptar.setEnabled(true);
            }
            this.actualizarTabla();
        

        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }

     }
     public boolean  llenarDatos(){
         Boolean estado=false;
        try {
           if( GestionPedidosDelegate.getInstance().registrarStock(listadetallesInventario)){
              estado=true;
           }
        } catch (Exception ex) {
          estado=false;
        }
         return estado;
     }
     public List<DetalleInventarioTO> recorrerTabla(){
          List<DetalleInventarioTO> detalles= new ArrayList<DetalleInventarioTO>();
         if(paginaActual>=paginas){
             int indice= this.paginaActual*15;
             for(int i=indice; i<listadetallesInventario.size(); i++){
                 detalles.add(listadetallesInventario.get(i));
             }
             return detalles;
         }else{
             int indice= this.paginaActual*15;
             for(int i=indice; i<indice+15; i++){
                 detalles.add(listadetallesInventario.get(i));
             }
         }
         
         return detalles;
     }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingSubAlmacen1 = new administracion.BeanBinding.CboBeanBindingSubAlmacen();
        cboBeanBindingAlmacen1 = new administracion.BeanBinding.cboBeanBindingAlmacen();
        cboBeanBindingZona1 = new administracion.BeanBinding.CboBeanBindingZona();
        cboBeanBindingEmpresa1 = new administracion.BeanBinding.CboBeanBindingEmpresa();
        jLabel5 = new javax.swing.JLabel();
        jlbInventario = new javax.swing.JLabel();
        jbtGenerar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbDetalleInventario = new javax.swing.JTable();
        jbtAnterior = new javax.swing.JButton();
        jbtSiguiente = new javax.swing.JButton();
        jbtAnteriort = new javax.swing.JButton();
        jbtSiguientet = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jblTotal = new javax.swing.JLabel();
        jblPaginaActual = new javax.swing.JLabel();
        jbtAceptar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jcbEmpresa = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();

        setIconifiable(true);
        setTitle("REGISTRAR STOCK FISICO");

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("INVENTARIO:");

        jlbInventario.setFont(new java.awt.Font("Arial", 1, 12));

        jbtGenerar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtGenerar.setMnemonic('G');
        jbtGenerar.setText("GENERAR");
        jbtGenerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtGenerarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "STOCK FISICO DE SUMINISTROS", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 255))); // NOI18N

        jtbDetalleInventario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "AMBIENTE", "PABELLON", "ESTANTE", "CASILLA", "SUMINISTRO", "DESCRIPCION", "UNIDAD", "STOCK ACTUAL", "STOCK FISICO"
            }
        ));
        jScrollPane1.setViewportView(jtbDetalleInventario);

        jbtAnterior.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\1leftarrow.png")); // NOI18N
        jbtAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAnteriorActionPerformed(evt);
            }
        });

        jbtSiguiente.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\1rightarrow.png")); // NOI18N
        jbtSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSiguienteActionPerformed(evt);
            }
        });

        jbtAnteriort.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\2leftarrow.png")); // NOI18N
        jbtAnteriort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAnteriortActionPerformed(evt);
            }
        });

        jbtSiguientet.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\2rightarrow.png")); // NOI18N
        jbtSiguientet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSiguientetActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("PAGINA:");

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel4.setText("/");

        jblTotal.setFont(new java.awt.Font("Arial", 1, 12));
        jblTotal.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jblTotal.setText("0");

        jblPaginaActual.setFont(new java.awt.Font("Arial", 1, 12));
        jblPaginaActual.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jblPaginaActual.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jblPaginaActual, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(84, 84, 84)
                .addComponent(jbtAnteriort)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtAnterior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtSiguiente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtSiguientet))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 692, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbtAnterior, jbtAnteriort, jbtSiguiente, jbtSiguientet});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jblPaginaActual, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
                            .addComponent(jLabel3))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtAnterior)
                        .addComponent(jbtSiguiente)
                        .addComponent(jbtAnteriort, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbtSiguientet, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jbtAnterior, jbtAnteriort, jbtSiguiente});

        jbtAceptar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbtAceptar.setMnemonic('A');
        jbtAceptar.setText("ACEPTAR");
        jbtAceptar.setEnabled(false);
        jbtAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarActionPerformed(evt);
            }
        });
        jbtAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtAceptarKeyPressed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Arial", 1, 12));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jButton2.setMnemonic('C');
        jButton2.setText("CERRAR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingEmpresa1, eLProperty, jcbEmpresa);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbEmpresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbEmpresaKeyPressed(evt);
            }
        });

        jCheckBox1.setFont(new java.awt.Font("Arial", 1, 12));
        jCheckBox1.setText("OTRAS EMPRESAS");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(242, 242, 242)
                        .addComponent(jbtAceptar)
                        .addGap(13, 13, 13)
                        .addComponent(jButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(18, 18, 18)
                                .addComponent(jlbInventario, javax.swing.GroupLayout.PREFERRED_SIZE, 485, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jCheckBox1)
                                .addGap(11, 11, 11)
                                .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jbtGenerar))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbInventario, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox1)
                    .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtGenerar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarActionPerformed

        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro que desea registrar los stocks fisicos?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            if(this.llenarDatos()){
                this.jbtAceptar.setEnabled(false);
                 Utiles_MensajesDialogo.mensajeExito();
            }else{
                 Utiles_MensajesDialogo.mensajeError("No se puedo registrar el stock fisico de los suministros");
            }
       
        }
    }//GEN-LAST:event_jbtAceptarActionPerformed

    private void jbtAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtAceptarKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtAceptar.doClick();
        }
}//GEN-LAST:event_jbtAceptarKeyPressed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            this.dispose();
        }
}//GEN-LAST:event_jButton2ActionPerformed

    private void jbtGenerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtGenerarActionPerformed
    if(this.jcbEmpresa.getSelectedIndex()>=0){

        try {
        this.jbtSiguiente.setEnabled(true);
        this.jbtSiguientet.setEnabled(true);
        //this.paginas=GestionPedidosDelegate.getInstance().iniciaConfiguracionInventario(3);
        llenarSuministros();
        this.jblTotal.setText(this.paginas+1+"");
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }
    else{
            Utiles_MensajesDialogo.mensajeAlerta("No ha seleccionado una empresa");
    }
       
    }//GEN-LAST:event_jbtGenerarActionPerformed

    private void jbtAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAnteriorActionPerformed
       /* if(estado){
            int res = javax.swing.JOptionPane.showConfirmDialog( this,"¿Ha realizado modificaciones desea actualizar los datos?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
            if(res==javax.swing.JOptionPane.YES_OPTION){
                if(this.llenarDatos()){
                    this.jbtAceptar.setEnabled(false);
                    Utiles_MensajesDialogo.mensajeExito();
                }else{
                     Utiles_MensajesDialogo.mensajeError("No se puedo registrar el stock fisico de los suministros");
                }

        }
        }*/
        try {
            estado=false;
            //this.paginaActual= GestionPedidosDelegate.getInstance().anteriorInventario();
            this.paginaActual--;
            this.actualizarTabla();
            if(this.paginaActual==0){
                this.jbtAnterior.setEnabled(false);
                this.jbtAnteriort.setEnabled(false);
            }
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }
         this.jbtSiguiente.setEnabled(true);
         this.jbtSiguientet.setEnabled(true);
         this.jblPaginaActual.setText(this.paginaActual+1+"");
    }//GEN-LAST:event_jbtAnteriorActionPerformed

    private void jbtSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSiguienteActionPerformed
       /* if(estado){
            int res = javax.swing.JOptionPane.showConfirmDialog( this,"¿Ha realizado modificaciones desea actualizar los datos?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
            if(res==javax.swing.JOptionPane.YES_OPTION){
                if(this.llenarDatos()){
                    this.jbtAceptar.setEnabled(false);
                   Utiles_MensajesDialogo.mensajeExito();
                }else{
                     Utiles_MensajesDialogo.mensajeError("No se puedo registrar el stock fisico de los suministros");
                }
        }
       }*/
        try {
            estado=false;
            //this.paginaActual=GestionPedidosDelegate.getInstance().siguienteInventario();
            this.paginaActual++;
            this.actualizarTabla();
            if(this.paginaActual==this.paginas){
                this.jbtSiguiente.setEnabled(false);
                this.jbtSiguientet.setEnabled(false);
            }
               
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior.setEnabled(true);
        this.jbtAnteriort.setEnabled(true);
        this.jblPaginaActual.setText(this.paginaActual+1+"");
    }//GEN-LAST:event_jbtSiguienteActionPerformed

    private void jbtAnteriortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAnteriortActionPerformed
         /*if(estado){
            int res = javax.swing.JOptionPane.showConfirmDialog( this,"¿Ha realizado modificaciones desea actualizar los datos?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
            if(res==javax.swing.JOptionPane.YES_OPTION){
                if(this.llenarDatos()){
                    this.jbtAceptar.setEnabled(false);
                    Utiles_MensajesDialogo.mensajeExito();
                }else{
                     Utiles_MensajesDialogo.mensajeError("No se puedo registrar el stock fisico de los suministros");
                }

        }
        }*/
        try {
            estado=false;
            //this.paginaActual=GestionPedidosDelegate.getInstance().anteriorTodoInventario();
            this.paginaActual=0;
            this.llenarSuministros();
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior.setEnabled(false);
        this.jbtAnteriort.setEnabled(false);
        this.jbtSiguiente.setEnabled(true);
        this.jbtSiguientet.setEnabled(true);
         this.jblPaginaActual.setText(this.paginaActual+1+"");
    }//GEN-LAST:event_jbtAnteriortActionPerformed

    private void jbtSiguientetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSiguientetActionPerformed
        /*if(estado){
            int res = javax.swing.JOptionPane.showConfirmDialog( this,"¿Ha realizado modificaciones desea actualizar los datos?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
            if(res==javax.swing.JOptionPane.YES_OPTION){
                if(this.llenarDatos()){
                    this.jbtAceptar.setEnabled(false);
                    Utiles_MensajesDialogo.mensajeExito();
                }else{
                     Utiles_MensajesDialogo.mensajeError("No se puedo registrar el stock fisico de los suministros");
                }

        }
        }*/
        try {
            estado=false;
           //this.paginaActual=GestionPedidosDelegate.getInstance().siguienteTodoInventario();
            this.paginaActual=paginas;
            this.actualizarTabla();
           // this.llenarSuministros();
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarStockFisico.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior.setEnabled(true);
        this.jbtAnteriort.setEnabled(true);
        this.jbtSiguiente.setEnabled(false);
        this.jbtSiguientet.setEnabled(false);
        this.jblPaginaActual.setText(this.paginaActual+1+"");
       
    }//GEN-LAST:event_jbtSiguientetActionPerformed

    private void jcbEmpresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbEmpresaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            if(this.jcbEmpresa.getSelectedIndex()>=0){
                this.jbtGenerar.requestFocus();
            }
        }
}//GEN-LAST:event_jcbEmpresaKeyPressed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if(this.jCheckBox1.isSelected()){
            this.jcbEmpresa.setEnabled(true);
        } else{
            this.jcbEmpresa.setEnabled(false);
        }
        this.llenarComboEmpresa();
}//GEN-LAST:event_jCheckBox1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.cboBeanBindingAlmacen cboBeanBindingAlmacen1;
    private administracion.BeanBinding.CboBeanBindingEmpresa cboBeanBindingEmpresa1;
    private administracion.BeanBinding.CboBeanBindingSubAlmacen cboBeanBindingSubAlmacen1;
    private administracion.BeanBinding.CboBeanBindingZona cboBeanBindingZona1;
    private javax.swing.JButton jButton2;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jblPaginaActual;
    private javax.swing.JLabel jblTotal;
    public javax.swing.JButton jbtAceptar;
    private javax.swing.JButton jbtAnterior;
    private javax.swing.JButton jbtAnteriort;
    private javax.swing.JButton jbtGenerar;
    private javax.swing.JButton jbtSiguiente;
    private javax.swing.JButton jbtSiguientet;
    private javax.swing.JComboBox jcbEmpresa;
    private javax.swing.JLabel jlbInventario;
    private javax.swing.JTable jtbDetalleInventario;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
